<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use App\Repositories\QuizRepository;

class Bet extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'quiz_item_id' => $this->quiz_item_id,
            'quiz_item_name' => $this->quiz_item_name,
            'copper' => $this->copper,
            'status' => $this->status,
            'odds' => $this->odds,
            'result' => $this->status == QuizRepository::BET_STATUS_FINISHED
                ? ($this->copper_result - $this->copper) : null,
            'user' => new User($this->user),
        ];
    }
}
